home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CommToolbox (original) / Sources / CConnection.c next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  14.6 KB  |  753 lines  |  [TEXT/KAHL]

  1. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞
  2.  
  3.     CConnection.c
  4.     
  5.     CommToolbox connection class.
  6.     
  7.     SUPERCLASS = CBureaucrat.
  8.     
  9.     Copyright © 1992-93 Romain Vignes. All rights reserved.
  10.     
  11. ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  12.  
  13. #include <CommResources.h>                    /* Apple includes */
  14. #include <Connections.h>
  15.  
  16. #include <CBartender.h>                        /* TCL includes */
  17. #include <CCluster.h>
  18. #include <CError.h>
  19. #include <Constants.h>
  20. #include <TBUtilities.h>
  21. #include <TCLUtilities.h>
  22.  
  23. #include "CConnection.h"                    /* Other includes */
  24.  
  25.  
  26. /* Constants & Macros */
  27.  
  28. #define CONN_STR_RES_ID        2100    /* Connection message resource ID */
  29.  
  30. #define NO_TOOL_STR_INDEX    1        /* No connection tool */
  31. #define BAD_TOOL_STR_INDEX    2        /* Bad connection tool */
  32. #define NO_REC_STR_INDEX    3        /* Connection record allocation error */
  33. #define CHOOSE_STR_INDEX    4        /* Tool setup error */
  34. #define OPEN_ERR_STR_INDEX    5        /* Error on opening */
  35. #define CLOSE_ERR_STR_INDEX 6        /* Error on closing */
  36. #define WAIT_ERR_STR_INDEX    7        /* Waiting impossible */
  37.  
  38. #define H_CHOOSE_POS        10        /* Setup dialog position */
  39. #define V_CHOOSE_POS        40
  40.  
  41. #define BREAK_DELAY            5        /* Approximately 80 ms */
  42.  
  43. #define FIRST_CONN_CMD        cmdConnChoose    /* First connection command */
  44. #define LAST_CONN_CMD        cmdConnListen    /* Last connection command */
  45.  
  46. #define RESET_ALRT_ID        2100    /* Reset alert resource ID */
  47.  
  48.  
  49. /* Application globals */
  50.  
  51. extern CBartender    *gBartender;
  52. extern CError        *gError;
  53.  
  54.  
  55. /* Class variables initialization */
  56.  
  57. CCluster *CConnection::cConnList = NULL;
  58.  
  59.  
  60.  
  61. /*
  62.  * cIsConnectionCmd
  63.  *
  64.  * Command related to the connection object
  65.  *
  66.  * theCmd:    command to analyse
  67.  *
  68.  * Return TRUE if the command is a connection command
  69.  *
  70.  */
  71.  
  72. Boolean CConnection::cIsConnectionCmd(long theCmd)
  73. {
  74.     return ((theCmd >= FIRST_CONN_CMD) && (theCmd <= LAST_CONN_CMD));
  75. }
  76.  
  77.  
  78. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  79.  
  80. /*
  81.  * cCheckToolName
  82.  *
  83.  * Checking existence of a tool by its name
  84.  *
  85.  * toolName:    name of the tool (Pascal string)
  86.  *
  87.  * Return cmGenericError if the tool is not present
  88.  *
  89.  */
  90.  
  91. OSErr CConnection::cCheckToolName(Str31 toolName)
  92. {
  93.     return(CMGetProcID(toolName));
  94. }    
  95.  
  96.  
  97. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  98.  
  99. /*
  100.  * cConnIdle
  101.  *
  102.  * Idle time for each connection object
  103.  *
  104.  *
  105.  */
  106.  
  107.          /* Idle routine for each connection object */
  108.  
  109.         static void    Conn_Idle(CConnection *theConn)
  110.         {
  111.             theConn->DoIdle();
  112.         }
  113.  
  114.  
  115. void CConnection::cConnIdle(void)
  116. {
  117.     if (cConnList != NULL)        /* List exists ? */
  118.         cConnList->DoForEach((EachFunc) Conn_Idle);
  119. }    
  120.  
  121.  
  122. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  123.  
  124. /*
  125.  * cInitManager
  126.  *
  127.  * Connection Manager Initialization
  128.  *
  129.  */
  130.  
  131. void CConnection::cInitManager(void)
  132. {
  133.     InitCM();
  134. }    
  135.  
  136.  
  137. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  138.  
  139. /*
  140.  * cGetCMVersion
  141.  *
  142.  * return the version of the Connection Manager
  143.  *
  144.  */
  145.  
  146. short CConnection::cGetCMVersion(void)
  147. {
  148.     return CMGetCMVersion();
  149. }    
  150.  
  151.  
  152. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  153.  
  154. /*
  155.  * IConnection
  156.  *
  157.  * Initialisation of the connection object
  158.  *
  159.  * aSupervisor:            object supervisor in the command chain
  160.  * toolName:            name of the connection tool to be used ("" -> défault)
  161.  * flags:(CM)            how to use the connection tool
  162.  * desiredSizes:(CM)    desired sizes of sending and receiving buffers
  163.  * refcon:(CM)            available for the application
  164.  * userData:(CM)        available for the application
  165.  *
  166.  * Parameters followed by CM are exact required parameters for creating a
  167.  * connection record.
  168.  *
  169.  */
  170.  
  171. void CConnection::IConnection(CBureaucrat *aSupervisor,Str31 toolName,
  172.                                 CMRecFlags flags,CMBufferSizes desiredSizes,
  173.                                 long refCon, long userData)
  174. {
  175.     ConnHandle    theConn;
  176.     OSErr        theErr;
  177.     Str31        tName;
  178.     short        toolProcID;
  179.     Boolean        savedAlloc;
  180.     
  181.     CBureaucrat::IBureaucrat(aSupervisor);    /* Initialize superclass */
  182.     
  183.     if (toolName[0] == 0)    {                /* Default tool ? */
  184.     
  185.         theErr = CRMGetIndToolName(classCM,1,tName);
  186.                 
  187.         if ((tName[0] == 0)    || (theErr != cmNoErr))         /* Error checking */
  188.             Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,NO_TOOL_STR_INDEX));
  189.             
  190.         toolProcID = CMGetProcID(tName);            /* Default tool ID */
  191.     }
  192.     else    {
  193.         toolProcID = CMGetProcID(toolName);            /* Specified tool ID */    
  194.     }
  195.         
  196.     if (toolProcID == cmGenericError)    {        /* No corresponding tool */
  197.         Failure(cmNoTools,SpecifyMsg(CONN_STR_RES_ID,BAD_TOOL_STR_INDEX));
  198.     }
  199.  
  200.     savedAlloc = SetAllocation(kAllocCanFail);
  201.     
  202.     theConn = CMNew(toolProcID,flags,desiredSizes,refCon,userData);
  203.     
  204.     SetAllocation(savedAlloc);
  205.     
  206.     FailNIL(theConn);            /* Connection created ? */
  207.  
  208.     MoveHHi((Handle)theConn);    /* Heap fragmentation… */
  209.     
  210.     itsConn = theConn;
  211.     
  212.     if (cConnList == NULL)    {            /* first connection object ? */
  213.         cConnList = new(CCluster);
  214.         cConnList->ICluster();
  215.     }
  216.     
  217.     cConnList->Add(this);                /* Connection addition */
  218.         
  219.     this->connOpen = FALSE;
  220.     
  221.     this->active = FALSE;
  222. }
  223.  
  224.  
  225. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  226.  
  227. /*
  228.  * Dispose
  229.  *
  230.  * Dispose of a connection object
  231.  *
  232.  */
  233.  
  234. void CConnection::Dispose(void)
  235. {
  236.     ASSERT(cConnList != NULL);
  237.     
  238.     cConnList->Remove(this);            /* Dispose of the Connection */
  239.     
  240.     if (cConnList->IsEmpty())
  241.         ForgetObject(cConnList);        /* Dispose of the cluster */
  242.  
  243.     CMDispose(itsConn);                    /* Dispose of the connection record */
  244.     itsConn = NULL;
  245.     
  246.     inherited::Dispose();                /* Pass message to its superclass */
  247. }
  248.  
  249.  
  250. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  251.  
  252. /*
  253.  * UpdateMenus
  254.  *
  255.  * Connection related menus updating
  256.  *
  257.  */
  258.  
  259. void CConnection::UpdateMenus(void)
  260. {
  261.     
  262.     gBartender->EnableCmd(cmdConnChoose);        /* Setup command */
  263.     
  264.     gBartender->EnableCmd(cmdConnReset);        /* Connection reset */
  265.     
  266.     if (this->IsOpen())    {                        /* Connection open ? */
  267.         gBartender->EnableCmd(cmdConnClose);
  268.         gBartender->EnableCmd(cmdConnBreak);
  269.     }
  270.     else    {
  271.         gBartender->EnableCmd(cmdConnOpen);
  272.         gBartender->EnableCmd(cmdConnListen);
  273.     }
  274. }
  275.  
  276.  
  277. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  278.  
  279. /*
  280.  * DoCommand
  281.  *
  282.  * Handle connection related commands
  283.  *
  284.  * theCommand:    command to be executed
  285.  *
  286.  */
  287.  
  288. void CConnection::DoCommand(long theCommand)
  289. {
  290.     switch (theCommand)    {        
  291.     
  292.         case cmdConnChoose:        /* Connection tool setup */
  293.             this->ConnectionChoose();
  294.             break;
  295.             
  296.         case cmdConnOpen:        /* Connection opening */
  297.             this->OpenConnection(FALSE,NULL,0L);
  298.             break;
  299.             
  300.         case cmdConnListen:        /* Connection listening */
  301.             this->ListenConnection(FALSE,NULL,0L);
  302.             break;
  303.             
  304.         case cmdConnClose:        /* Connection waiting */
  305.             this->CloseConnection(FALSE,NULL,0L,TRUE);
  306.             break;
  307.             
  308.         case cmdConnReset:        /* Connection reset */
  309.             this->Reset();
  310.             break;
  311.             
  312.         case cmdConnBreak:        /* BREAK signal send */
  313.             this->SendBreak();
  314.             break;
  315.             
  316.         default:                /* Unknown command */
  317.             break;
  318.     }
  319. }
  320.  
  321.  
  322. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  323.  
  324. /*
  325.  * ConnectionChoose
  326.  *
  327.  * Connection tool setup
  328.  *
  329.  */
  330.  
  331. void CConnection::ConnectionChoose(void)
  332. {
  333.     short        retCode;
  334.     Point        where;
  335.     ConnHandle    hConn;
  336.     
  337.     hConn = this->itsConn;
  338.     
  339.     SetPt(&where,H_CHOOSE_POS,V_CHOOSE_POS);    /* Dialog position */
  340.                                                 
  341.     retCode = CMChoose(&hConn,where,NULL);
  342.     
  343.     this->itsConn = hConn;
  344.  
  345.     switch (retCode)    {        
  346.         case chooseCancel:        /* Forget changes */
  347.             break;
  348.             
  349.         case chooseOKMinor:        /* Same tool, changed config */
  350.         case chooseOKMajor:        /* Changed tool */
  351.         
  352.             active = FALSE;
  353.             Activate();
  354.         
  355.             itsSupervisor->Notify(NULL);     /* Document updated */
  356.             
  357.             break;
  358.             
  359.         default:                /* Unknown code (error) */
  360.             SysBeep(3);
  361.             gError->PostAlert(CONN_STR_RES_ID,CHOOSE_STR_INDEX);
  362.             break;    
  363.     }
  364. }
  365.  
  366.  
  367. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  368.  
  369. /*
  370.  * SetConfig
  371.  *
  372.  * Connection configuration change
  373.  *
  374.  * theConfig:    new configuration (C string)
  375.  *
  376.  * Return:        negative value: error (-1 -> unknown error)
  377.  *                positive value: stop index of the parser
  378.  *                cmNoErr if everything is OK
  379.  *
  380.  */
  381.  
  382. short CConnection::SetConfig(char *theConfig)
  383. {
  384.     short retCode;
  385.     
  386.     retCode = CMSetConfig(itsConn,theConfig);
  387.     
  388.     return retCode;
  389. }    
  390.  
  391.  
  392. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  393.  
  394. /*
  395.  * GetToolName
  396.  *
  397.  * Return the name of the current tool
  398.  *
  399.  * toolName:    tool name (Pascal string)
  400.  *
  401.  */
  402.  
  403. void CConnection::GetToolName(Str31 toolName)
  404. {
  405.     SignedByte    savedState;
  406.     
  407.     savedState = HGetState(itsConn);
  408.     HLock(itsConn);
  409.  
  410.     CMGetToolName((*itsConn)->procID,toolName);
  411.     
  412.     HSetState(itsConn,savedState);
  413. }    
  414.  
  415.  
  416. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  417.  
  418. /*
  419.  * GetConfig
  420.  *
  421.  * Return a C string describing the current config of the connection
  422.  *
  423.  * Return a pointer on the string
  424.  *
  425.  */
  426.  
  427. Ptr CConnection::GetConfig(void)
  428. {
  429.     return(CMGetConfig(itsConn));
  430. }    
  431.  
  432.  
  433. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  434.  
  435. /*
  436.  * getStatus
  437.  *
  438.  * Return the connection status
  439.  *
  440.  * sizes:    Buffers sizes (sortie)
  441.  * flags:    Connection status (sortie)
  442.  *
  443.  * Return an error code
  444.  *
  445.  */
  446.  
  447. OSErr CConnection::getStatus(CMBufferSizes *sizes,CMStatFlags *flags)
  448. {
  449.     return(CMStatus(itsConn,*sizes,flags));
  450. }    
  451.  
  452.  
  453. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  454.  
  455. /*
  456.  * OpenConnection
  457.  *
  458.  * Connection opening
  459.  *
  460.  * async:        Opening mode (synchrone or asynchrone)
  461.  * completor:    asynchrone callback
  462.  * timeOut:        time period within which the opening must be completed
  463.  *
  464.  */
  465.  
  466. void CConnection::OpenConnection(Boolean async,ProcPtr completor,long timeOut)
  467. {
  468.     OSErr    theErr;
  469.     
  470.     theErr = CMOpen(itsConn,async,completor,timeOut);
  471.     
  472.     if (theErr == cmNoErr)    {
  473.         this->connOpen = TRUE;
  474.         BroadcastChange(connOpenInd,NULL);
  475.     }
  476. }    
  477.  
  478.  
  479. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  480.  
  481. /*
  482.  * ListenConnection
  483.  *
  484.  * Connection listening
  485.  *
  486.  * async:        Listening mode (synchrone or asynchrone)
  487.  * completor:    asynchrone callback
  488.  * timeOut:        time period within which the listening must be completed
  489.  *
  490.  */
  491.  
  492. void CConnection::ListenConnection(Boolean async,ProcPtr completor,long timeOut)
  493. {
  494.     OSErr    theErr;
  495.     
  496.     theErr = CMListen(itsConn,async,completor,timeOut);
  497. }    
  498.  
  499.  
  500. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  501.  
  502. /*
  503.  * CloseConnection
  504.  *
  505.  * Connection closing
  506.  *
  507.  * async:        Closing mode (synchrone or asynchrone)
  508.  * completor:    asynchrone callback
  509.  * timeOut:        time period within which the closing must be completed
  510.  * now:            immediately closing
  511.  *
  512.  */
  513.  
  514. void CConnection::CloseConnection(Boolean async,ProcPtr completor,long timeOut,
  515.                                     Boolean now)
  516. {
  517.     OSErr    theErr;
  518.     
  519.     theErr = CMClose(itsConn,async,completor,timeOut,now);
  520.     
  521.     if (theErr == cmNoErr)    {
  522.         this->connOpen = FALSE;
  523.         BroadcastChange(connCloseInd,NULL);
  524.     };
  525. }    
  526.  
  527.  
  528. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  529.  
  530. /*
  531.  * IsOpen
  532.  *
  533.  * Connection opening test
  534.  *
  535.  * Return TRUE if the connection is open
  536.  *
  537.  */
  538.  
  539. Boolean CConnection::IsOpen(void)
  540. {
  541.     CMBufferSizes    sizes;
  542.     CMStatFlags        flags;
  543.     OSErr            theErr;
  544.     
  545.     theErr = this->getStatus(&sizes,&flags);
  546.     
  547.     if (theErr == cmNoErr)
  548.         if (flags & cmStatusOpen)        /* Connection open ? */
  549.             return TRUE;
  550.         else
  551.             return FALSE;
  552.     else
  553.         return FALSE;
  554. }    
  555.  
  556.  
  557. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  558.  
  559. /*
  560.  * DataAvail
  561.  *
  562.  * Data available
  563.  *
  564.  * Return the number of available characters
  565.  *
  566.  */
  567.  
  568. long CConnection::DataAvail(void)
  569. {
  570.     CMBufferSizes    sizes;
  571.     CMStatFlags        flags;
  572.     OSErr            theErr;
  573.     
  574.     theErr = this->getStatus(&sizes,&flags);
  575.     
  576.     if (theErr == cmNoErr)
  577.         if (flags & cmStatusDataAvail)        /* Data available ? */
  578.             return sizes[cmDataIn];        /* Return receiving buffer size */
  579.         else
  580.             return 0;
  581.     else
  582.         return 0;
  583. }    
  584.  
  585.  
  586. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  587.  
  588. /*
  589.  * DataRead
  590.  *
  591.  * Reading of available data
  592.  *
  593.  * inBuffer:    Receiving buffer
  594.  * buffSize:    Number of chars to read
  595.  * async:        Reading mode (asynchrone or synchrone)
  596.  * completor:    Reading callback
  597.  * timeOut:        time period within which the reading must be completed
  598.  * flags:        end-of-message indicator
  599.  *
  600.  * Return an error code
  601.  *
  602.  */
  603.  
  604. OSErr CConnection::DataRead(Ptr inBuffer,long *buffSize,Boolean async,
  605.                             ProcPtr completor,long timeOut,CMFlags *flags)
  606. {
  607.     return (CMRead(itsConn,inBuffer,buffSize,cmData,async,completor,timeOut,
  608.                     flags));
  609. }    
  610.  
  611.  
  612. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  613.  
  614. /*
  615.  * DoIdle
  616.  *
  617.  * Idle time of the application
  618.  *
  619.  */
  620.  
  621. void CConnection::DoIdle(void)
  622. {
  623.     CMIdle(itsConn);
  624.     
  625.     if (!(this->IsOpen()) && this->connOpen)    {
  626.         this->connOpen = FALSE;
  627.         BroadcastChange(connCloseInd,NULL);
  628.     };
  629. }                                        
  630.  
  631.  
  632. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  633.  
  634. /*
  635.  * DataWrite
  636.  *
  637.  * Data writing
  638.  *
  639.  * inBuffer:    Sending buffer
  640.  * buffSize:    Number of chars to send
  641.  * async:        Writing mode (synchrone or asychrone)
  642.  * completor:    Asynchrone writing callback
  643.  * timeOut:        time period within which the writing must be completed
  644.  * flags:        end-of-message indicator
  645.  *
  646.  * Return an error code
  647.  *
  648.  */
  649.  
  650. OSErr CConnection::DataWrite(Ptr inBuffer,long *buffSize,Boolean async,
  651.                             ProcPtr completor,long timeOut,CMFlags flags)
  652. {
  653.     return (CMWrite(itsConn,inBuffer,buffSize,cmData,async,completor,timeOut,
  654.                     flags));
  655. }    
  656.  
  657.  
  658. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  659.  
  660. /*
  661.  * Activate
  662.  *
  663.  * Connection activation
  664.  *
  665.  */
  666.  
  667. void CConnection::Activate(void)
  668. {
  669.     if (!active)    {
  670.         CMActivate(itsConn,TRUE);
  671.         active = TRUE;
  672.     }
  673. }                                        
  674.  
  675.  
  676. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  677.  
  678. /*
  679.  * Deactivate
  680.  *
  681.  * Connection desactivation
  682.  *
  683.  */
  684.  
  685. void CConnection::Deactivate(void)
  686. {
  687.     if (active)    {
  688.         CMActivate(itsConn,FALSE);
  689.         active = FALSE;
  690.     }
  691. }                                        
  692.  
  693.  
  694. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  695.  
  696. /*
  697.  * Reset
  698.  *
  699.  * Connection reset
  700.  *
  701.  */
  702.  
  703. void CConnection::Reset(void)
  704. {
  705.     short    response;
  706.     
  707.     PositionDialog('ALRT', RESET_ALRT_ID);
  708.     
  709.     InitCursor();
  710.     
  711.     response = Alert(RESET_ALRT_ID, NULL);
  712.         
  713.     if (response == answerNO)
  714.         CMReset(itsConn);
  715. }                                        
  716.  
  717.  
  718. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  719.  
  720. /*
  721.  * SendBreak
  722.  *
  723.  * BREAK signal sending
  724.  *
  725.  */
  726.  
  727. void CConnection::SendBreak(void)
  728. {
  729.     CMBreak(itsConn,BREAK_DELAY,FALSE,NULL);
  730. }                                        
  731.  
  732.  
  733. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  734.  
  735. /*
  736.  * GetEnvirons
  737.  *
  738.  * Return the connection environs
  739.  *
  740.  * theEnvirons: Pointer on the environs record
  741.  *
  742.  * Return an error code
  743.  *
  744.  */
  745.  
  746. OSErr CConnection::GetEnvirons(ConnEnvironRecPtr theEnvirons)
  747. {
  748.     return(CMGetConnEnvirons(itsConn,theEnvirons));
  749. }    
  750.  
  751.  
  752. /* ∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞∞ */
  753.